package game.ai.aoi;

import game.ai.scene.IScene;
import game.ai.scene.SceneObject;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class AoiSpace {

	public IScene scene;

	public Map<Integer, AoiObject> objMap = new HashMap<Integer, AoiObject>();

	public List<AoiHotPair> hotPairList = new LinkedList<AoiHotPair>();

	public Set<AoiObject> watcherMove = new HashSet<AoiObject>();

	public Set<AoiObject> watcherStatic = new HashSet<AoiObject>();

	public Set<AoiObject> markerMove = new HashSet<AoiObject>();

	public Set<AoiObject> markerStatic = new HashSet<AoiObject>();

	public AoiSpace(IScene iScene) {
		this.scene = iScene;
	}

	public void aoiEnterMsg(int watcherId, int markerId) {
		if (scene == null) {
			System.out.println(String.format("<<<<< Enter Msg :: watcher=%s,marker=%s", watcherId, markerId));
			return;
		}
		SceneObject watcherObj = scene.getObjById(watcherId);
		SceneObject markerObj = scene.getObjById(markerId);
		if (watcherObj != null) {
			watcherObj.getEyeShotManager().addInMyEyeShot(markerObj, false);
		}
	}

	public void aoiLeaveMsg(int watcherId, int markerId) {
		if (scene == null) {
			System.out.println(String.format(">>>>>Leave Msg :: watcher=%s,marker=%s", watcherId, markerId));
			return;
		}
		SceneObject watcherObj = scene.getObjById(watcherId);
		SceneObject markerObj = scene.getObjById(markerId);
		if (watcherObj != null) {
			watcherObj.getEyeShotManager().removeFromMyEyeShot(markerObj);
		}
	}

}

class AoiHotPair {

	public AoiObject watcher;

	public AoiObject marker;

	public int watcherVersion;

	public int markerVersion;

}

class AoiObject {

	public int id;

	public int version;

	public byte mode;

	public short[] posPair;

	public short[] lastPosition;

	public AoiObject(int id) {
		this.id = id;
		this.posPair = new short[] { 0, 0 };
		this.lastPosition = new short[] { 0, 0 };
	}

}
